<?php

class DefaultController extends Controller
{
	public $layout='//layouts/main';
	
	public function init(){
		Yii::app()->theme = 'frontend';
		parent::init();
	}
	
	public function actionIndex($page = 1)
	{
		$dataProvider=new CActiveDataProvider('Event', array(
			'criteria'=>array(
					'condition'=>'is_published=1',
					'order'=>'created DESC',
			),
			'pagination'=>array(
				'pageSize'=> 10,
				'route' => '/events',
				'pageVar'=>'page',
			),
		));
		//CVarDumper::dump($dataProvider->getData(),10,true);
		$this->render('index', array(
			'dataProvider'=>$dataProvider,
		));
	}
	
	public function actionView($alias = null){
		if(empty($alias))
			throw new CHttpException(400, Yii::t('app', 'Your request is invalid.'));
			
		$model = Event::model()->findByAttributes(array(
			'alias' => $alias
		));
		
		if($model === null)
			throw new CHttpException(400, Yii::t('app', 'Your request is invalid.'));
		
		$otherNews = Event::model()->findAll(array(
			'condition' => 'id<>:current_events_id',
			'params' => array(
				':current_events_id' => $model->id
			),
			'limit' => 5,
		));
		
		$this->render('view', array(
				'model' => $model,
				'otherEvents' => $otherNews
		));
	}
}